package com.yupi.mianshiya.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 定义交换机
    @Bean
    public DirectExchange taskExchange() {
        return new DirectExchange("task.exchange");
    }

    // 定义队列
    @Bean
    public Queue taskQueue() {
        return new Queue("batch-task-queue", true); // durable: 持久化队列
    }

    // 定义绑定关系
    @Bean
    public Binding taskBinding(DirectExchange taskExchange, Queue taskQueue) {
        return BindingBuilder.bind(taskQueue).to(taskExchange).with("task.routingKey");
    }
}